package org.zachary.commonservice.strategy.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.zachary.commonmodule.entity.MqTransmissionJson;
import org.zachary.commonservice.entity.CreditScoreStrategy;
import org.zachary.commonservice.entity.ServiceType;
import org.zachary.commonservice.strategy.CreditStrategy;
import org.zachary.commonservice.strategy.cache.StrategyCache;

@Component
public class WaterGuardian implements CreditStrategy {
    @Autowired
    private StrategyCache cache;
    @Override
    public ServiceType getServiceType() {
        return ServiceType.WaterGuardian;
    }
    @Override
    public int calculate(MqTransmissionJson message, int currentScore) {
        CreditScoreStrategy config = loadConfig(message.getServiceType(), currentScore);
        if (config == null) {
            throw new IllegalStateException("未找到匹配的信用策略配置");
        }
        return config.getAddScore();
    }
    private CreditScoreStrategy loadConfig(Integer serviceTypeCode, int userScore) {
        ServiceType serviceType = ServiceType.values()[serviceTypeCode];
        return cache.getStrategy(serviceType, userScore);
    }
}
